package com.hp.attendance.serlvet.history.InService;

import com.hp.attendance.entity.Department;
import com.hp.attendance.entity.Employee;
import com.hp.attendance.entity.Position;
import com.hp.attendance.service.EmployeeBysService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/updPreEmployee")
public class EmployeePreUpdServlet extends HttpServlet {
    private EmployeeBysService employeeBysService = new EmployeeBysService();


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
//-------------------------------------回显员工数据--------------------------------------
            String employee_number = req.getParameter("employee_number");
            Employee employee = employeeBysService.getEmployeeByNum(Integer.parseInt(employee_number));
            req.setAttribute("employee",employee);

            //显示部门下拉列表
            List<Department> departments = employeeBysService.getDepartment();
            req.setAttribute("departments",departments);

            //显示职称下拉列表
            List<Position> positions = employeeBysService.getPosition();
            req.setAttribute("positions",positions);

            //跳转
            req.getRequestDispatcher("/pages/employee_update.jsp").forward(req,resp);
        }


        catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
